#!/usr/bin/python

#convert mol2 files in directory to pdb files and write pymol script to load them in pymol

import sys
from openeye.oechem import *

in_file = oemolistream(sys.argv[1])
dir = sys.argv[2]
pymol_script = open(sys.argv[2] + '.pml', 'w')

mol = OEGraphMol()

while OEReadMolecule(in_file, mol):
	title = mol.GetTitle()
	print title
	out_file = oemolostream(dir + '/' + title + '.pdb')
	OEWriteMolecule(out_file, mol)
	out_file.close()
	pymol_script.write('load ' + dir + '/' + title + '.pdb\n')
	
in_file.close()
pymol_script.close()
